﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBOffice.Models;

namespace PBOffice.BLL
{
    public class DeptExpManager
    {
        public List<DepartmentExp> GetDeptExp()
        {
            List<DepartmentExp> list = new List<DepartmentExp>();
            List<Department> dept = new DeptManager().GetAllDepartment();
            foreach (Department item in dept)
            {
                int count = new StaffManager().GetCountByDeptPosName(item.DeptName, "", "");

                if (new DeptManager().GetCountByParentId(item.DeptId)!=0)
                {
                    foreach (Department dep in new DeptManager().GetAllDeptByParentId(item.DeptId))
                    {
                        count += new StaffManager().GetCountByDeptPosName(dep.DeptName, "", "");
                        if (new DeptManager().GetCountByParentId(dep.DeptId) != 0)
                        {
                            foreach (Department dep1 in new DeptManager().GetAllDeptByParentId(dep.DeptId))
                            {
                                count += new StaffManager().GetCountByDeptPosName(dep1.DeptName, "", "");
                            }
                        }
                    }
                }
                DepartmentExp exp = new DepartmentExp();
                exp.Branch = item.Branch;
                exp.DeptId = item.DeptId;
                exp.DeptName = item.DeptName;
                exp.Num = count;
                exp.ParentId = item.ParentId;
                list.Add(exp);
            }
            return list;
        }
    }
}
